home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.02 Feb 90 / Mouse Source / TrackUpdate.c < prev   
Encoding:
C/C++ Source or Header  |  1989-07-22  |  2.7 KB  |  119 lines  |  [TEXT/KAHL]

  1. /*                                            TrackUpdate.c                                        */
  2. /*
  3.  * Copyright © 1989 Martin Minow. All rights reserved.
  4.  *
  5.  * Update the track data.  User programs call TrackUpdate,
  6.  * internally, _Track_do_update is called.
  7.  *
  8.  * void
  9.  * TrackUpdate(rectp, track_handle)
  10.  * Rect                    *rectp;
  11.  * TrackHandle    track_handle;
  12.  *
  13.  * void
  14.  * _Track_do_update(tr, rectp)
  15.  * TrackPtr            tr;
  16.  * Rect                    *rectp;
  17.  */
  18.  
  19. #include "TrackEdit.h"
  20. #define TR    (*tr)
  21.  
  22. static void            drawtext(TrackPtr, Rect *);
  23.  
  24. void
  25. TrackUpdate(update_rect_ptr, track_handle)
  26. Rect                *update_rect_ptr;
  27. TrackHandle    track_handle;
  28. {
  29.         register TrackPtr    tr;
  30.         _Track_state            state;
  31.         
  32.         tr = _Track_lock(track_handle, &state);
  33.         _Track_do_update(tr, update_rect_ptr);
  34.         _Track_unlock(&state);
  35. }
  36.  
  37. void
  38. _Track_do_update(tr, update_rect_ptr)
  39. register TrackPtr    tr;
  40. Rect                            *update_rect_ptr;
  41. {
  42.         RgnHandle                    clip;
  43.         Rect                            view;
  44.  
  45.         /*
  46.          * Get a copy of the current grafPort's clipping
  47.          * region (TrackLock has already clipped the window
  48.          * to the TrackRecord's viewRect) and intersect that
  49.          * with the update_rect.  Don't bother restoring
  50.          * the clipRgn: TrackUnlock will do that.
  51.          */
  52.          clip = NewRgn();
  53.         RectRgn(clip, update_rect_ptr);
  54.         SectRgn(clip, thePort->clipRgn, thePort->clipRgn);
  55.         /*
  56.          * Draw any text inside the update rectangle, then.
  57.          * if the window is active, invert any hilited text.
  58.          */
  59.         drawtext(tr, update_rect_ptr);
  60.         if (_Track_is_set(tr, _Track_is_active)) {
  61.             _Track_hilite(tr, TR.selStart, TR.selEnd);
  62.             if (_Track_is_set(tr, _Track_caret_visible))
  63.                 _Track_invert_caret(tr);
  64.         }
  65.         DisposeRgn(clip);
  66. }
  67.  
  68. /*
  69.  * draw_text(track_ptr, draw_rect)
  70.  * Draw text onto the screen.  The caller has set
  71.  * the grafPort's clip rect.  The draw_rect defines
  72.  * the top and bottom of the data to be drawn.
  73.  */
  74. static void
  75. drawtext(tr, view)
  76. register TrackPtr    tr;
  77. Rect                            *view;
  78. {
  79.         register int            vpixel;
  80.         register long            first, last;
  81.         register int            t_width, w_width;
  82.         register int            hpixel;
  83.  
  84.         /*
  85.          * Locate the first and last rows to be drawn.
  86.          * Note that we may have a partial last line,
  87.          * so we try to draw one extra.
  88.          */
  89.         first = _Track_pixel_row(tr, view->top);
  90.         last = _Track_pixel_row(tr, view->bottom) + 1;
  91.         if (last >= TR.nLines)
  92.             last = TR.nLines;
  93.         /*
  94.          * Since the view rectange we are presented may not
  95.          * be aligned with our line grid, we compute our
  96.          * pen position so it's aligned with the top row.
  97.          */
  98.         vpixel = _Track_row_pixel(tr, first);
  99.         MoveHHi(TR.hText);
  100.         HLock(TR.hText);
  101.         while (first < last) {
  102.             if (first >= 0) {
  103.                 MoveTo(
  104.                     (INTEGER) _Track_h_origin(tr, first),
  105.                     vpixel
  106.                 );
  107.                 DrawText(
  108.                     *TR.hText,
  109.                     TR.lineStarts[first],
  110.                     TR.lineStarts[first + 1] - TR.lineStarts[first]
  111.                 );
  112.             }
  113.             vpixel += TR.lineHeight;
  114.             first++;
  115.         }
  116.         HUnlock(TR.hText);
  117. }
  118.  
  119.